package com.zxp.springboot.hello.gen;

import lombok.SneakyThrows;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import org.springframework.core.io.ClassPathResource;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zxp
 * @date 2021-08-26 17:48
 */
public class Mbg {

    @SneakyThrows
    public static void main(String[] args) {
        List<String> warnings = new ArrayList<>();

        // 如果已经存在生成过的文件是否进行覆盖
        boolean overwrite = true;
        ConfigurationParser cp = new ConfigurationParser(warnings);

        ClassPathResource resource = new ClassPathResource("generator-configuration.xml");
        Configuration config = cp.parseConfiguration(resource.getInputStream());

        DefaultShellCallback callback = new DefaultShellCallback(overwrite);

        MyBatisGenerator generator = new MyBatisGenerator(config, callback, warnings);
        generator.generate(null);

        System.out.println("生成成功！");
    }
}
